package com.sky.controller.admin;

import com.github.pagehelper.PageHelper;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: qs
 * @Date: 2025/2/19 10:18
 * @Description:
 **/
@RestController
@RequestMapping("/admin/category")
@Api(tags = "菜品分类相关接口")
@Slf4j
public class CategoryController {


    @Autowired
    private CategoryService categoryService;


    /**
     * 菜品分类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分类分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){

       PageResult pageResult=categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增菜品分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品分类")
    public Result<String> save(@RequestBody CategoryDTO categoryDTO){
        categoryService.save(categoryDTO);
        return Result.success();
    }


    /**
     * 修改菜品分类
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品分类")
    public Result<String> update(@RequestBody CategoryDTO categoryDTO){

        categoryService.update(categoryDTO);
        return Result.success();
    }


    /**
     * 删除菜品分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除菜品分类")
    public Result<String> delete(Long id){
        categoryService.delete(id);
        return Result.success();
    }


    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用菜品分类")
    public Result<String> updateStatus(@PathVariable Integer status,Long id){

        categoryService.updateStatus(status,id);
        return Result.success();
    }




}
